//
//  HYTypeList.m
//  HaiYue
//
//  Created by skyline on 2018/6/5.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYTypeList.h"
#import "HYGameTypeModel.h"
CGFloat const SearchCellHeardHeight = 25;
@interface HYTypeList()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, assign) CGFloat cellH;
@end
@implementation HYTypeList
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.delegate = self;
        self.dataSource = self;
        self.showsVerticalScrollIndicator = NO;
    }
    return self;
}

- (void)setList:(NSMutableArray *)list
{
    if (_list != list)
    {
        _list = list;
        [self reloadData];
    }
}

#pragma mark - UITableViewDataSource 事件
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.list.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

static NSString *identifier;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
identifier = [NSString stringWithFormat:@"searchCell%ld",(long)indexPath.section];
        HYTypeCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell)
        {
            cell = [[HYTypeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        cell.model= (HYGameTypeModel *)self.list[indexPath.section];
        self.cellH = CGRectGetHeight(cell.bounds);
        return cell;
    
}

#pragma mark - UITableViewDelegate 事件
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
     return self.cellH;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return SearchCellHeardHeight;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
  
        HYFillLabel *label = [[HYFillLabel alloc]initWithFrame:CGRectMake(0, 0, 60, SearchCellHeardHeight) typeOfshapeLayer:CCShapeLayerTypeRightHalfEllipse
                                                     attribute:@{HYTextColor:[UIColor whiteColor],HYTextFont:[UIFont systemFontOfSize:13]}];
    HYGameTypeModel *model= (HYGameTypeModel *)self.list[section];
    label.backgroundColor = THEME_COLOR;
    label.text = model.title;
        [view addSubview:label];
        [label mas_updateConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(view);
            make.left.equalTo(view);
            make.size.mas_equalTo(label.bounds.size);
        }];
        return view;
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
